'use strict';

module.exports = app => {
  const { router, controller, middleware } = app;
  /**
   * 用户
   */
  // 用户
  router.post('/api/user/wx/login', controller.business.user.wxLogin);
  router.post('/api/user/wx/getPhoneNumber', controller.business.user.getPhoneNumber);
  router.get('/api/user/wx/getUserQrCode', controller.business.user.getUserQrCode);
  router.get('/api/user/list', controller.business.user.list);
  router.resources('user', '/api/user', controller.business.user);
  // 地址
  router.get('/api/address/list', controller.business.address.list);
  router.resources('address', '/api/address', controller.business.address);
  // 出行人
  router.get('/api/traveler/list', controller.business.traveler.list);
  router.resources('traveler', '/api/traveler', controller.business.traveler);
  // 出行人订单关联
  router.get('/api/travelerOrder/list', controller.business.travelerOrder.list);
  router.resources('travelerOrder', '/api/travelerOrder', controller.business.travelerOrder);
  /**
   * 订单
   */
  // 产品
  router.get('/api/productCategory/list', controller.business.productCategory.list);
  router.resources('productCategory', '/api/productCategory', middleware.auth(), controller.business.productCategory);
  // 产品
  router.get('/api/product/list', controller.business.product.list);
  router.resources('product', '/api/product', middleware.auth(), controller.business.product);
  // 产品规格
  router.get('/api/productSpec/list', controller.business.productSpec.list);
  router.resources('productSpec', '/api/productSpec', controller.business.productSpec);
  // 产品SKU
  router.get('/api/productSku/list', controller.business.productSku.list);
  router.resources('productSku', '/api/productSku', controller.business.productSku);
  // SKU组合生成
  router.post('/api/productSku/generate', controller.business.productSku.generateSkuCombinations);
  // 检查SKU是否存在
  router.post('/api/productSku/check', controller.business.productSku.checkSkuExists);
  // 批量创建SKU
  router.post('/api/productSku/batch', controller.business.productSku.batchCreate);

  // 获取订单详情
  router.get('/api/order/detail', controller.business.order.detail);
  // 取消订单
  router.post('/api/order/cancel', controller.business.order.cancel);
  // 设置订单价格
  router.post('/api/order/price', controller.business.order.setPrice);
  // 申请退款
  router.post('/api/order/refund', controller.business.order.refund);
  router.post('/api/order/refund/confirm', controller.business.order.refundConfirm);
  router.post('/api/order/confirm', controller.business.order.confirm);
  router.post('/api/order/complete', controller.business.order.complete);
  
  router.resources('order', '/api/order', controller.business.order);
  // 订单子项
  router.get('/api/orderItem/list', controller.business.orderItem.list);
  router.resources('orderItem', '/api/orderItem', controller.business.orderItem);

  // 支付
  // 创建支付订单
  router.post('/api/payment/wx', controller.payment.wxPay.createPayment);
  // 支付回调
  router.post('/api/wxPay/paymentWxNotify', controller.payment.wxPay.paymentWxNotify);
  router.post('/api/wxPay/refundWxNotify', controller.payment.wxPay.refundWxNotify);
  /**
   * 通用
   */
  // 上传文件
  router.post('/api/upload/file', controller.common.upload.cos);
  router.get('/api/file/list', controller.common.file.list);
  router.resources('file', '/api/file', controller.common.file);
  // 配置
  router.get('/api/config/list', controller.business.config.list);
  router.get('/api/config/key/:key', controller.business.config.getByKey);
  router.resources('config', '/api/config', controller.business.config);
  // banner
  router.get('/api/banner/list', controller.common.banner.list);
  router.resources('banner', '/api/banner', controller.common.banner);
  // 文章
  router.get('/api/article/list', controller.business.article.list);
  router.resources('article', '/api/article', controller.business.article);
  // 通知
  router.get('/api/notice/list', controller.business.notice.list);
  router.resources('notice', '/api/notice', controller.business.notice);

    /**
   * 旅行产品
   */
  // 旅行分类
  router.get('/api/travelCategory/list', controller.business.travelCategory.list);
  router.resources('travelCategory', '/api/travelCategory', controller.business.travelCategory);
  // 目的地城市组
  router.get('/api/travel/destinationCityGroup', controller.business.travel.destinationCityGroup);
  // 旅行产品
  router.get('/api/travel/list', controller.business.travel.list);
  router.resources('travel', '/api/travel', middleware.auth(), controller.business.travel);
  // 旅行规格
  router.get('/api/travelSpec/list', controller.business.travelSpec.list);
  router.resources('travelSpec', '/api/travelSpec', controller.business.travelSpec);
  // 旅行SKU
  router.get('/api/travelSku/list', controller.business.travelSku.list);
  router.resources('travelSku', '/api/travelSku', controller.business.travelSku);
  // 批量删除
  router.post('/api/travelSkuStock/batchDelete', controller.business.travelSkuStock.batchDelete);
  // 旅行每日库存
  router.get('/api/travelSkuStock/list', controller.business.travelSkuStock.list);
  router.resources('travelSkuStock', '/api/travelSkuStock', controller.business.travelSkuStock);

  // 拼团订单的，团列表
  router.get('/api/travelOrder/list', controller.business.travelOrder.list);
  router.get('/api/travelOrder/groupList', controller.business.travelOrder.getGroupList);
  // 获取订单详情
  router.get('/api/travelOrder/detail', controller.business.travelOrder.detail);
  // 取消订单
  router.post('/api/travelOrder/cancel', controller.business.travelOrder.cancel);
  // 设置订单价格
  router.post('/api/travelOrder/price', controller.business.travelOrder.setPrice);
  // 确认行程
  router.post('/api/travelOrder/confirm', controller.business.travelOrder.confirmTravel);
  // 完成行程
  router.post('/api/travelOrder/complete', controller.business.travelOrder.completeTravel);
  // 申请退款
  router.post('/api/travelOrder/refund', controller.business.travelOrder.refund);
  router.post('/api/travelOrder/refund/confirm', controller.business.travelOrder.refundConfirm);
  // 订单子项
  router.get('/api/travelOrderItem/list', controller.business.travelOrderItem.list);


  // 支付
  // 创建支付订单
  router.post('/api/travelOrder/payment/wx', controller.payment.travelOrder.createPayment);
  // 支付回调
  router.post('/api/travelOrder/payment/wx/notify', controller.payment.travelOrder.paymentWxNotify);
  router.post('/api/travelOrder/payment/wx/refund/notify', controller.payment.travelOrder.refundWxNotify);

  router.get('/api/travelShareOrder/list', controller.business.travelShareOrder.list);
  router.post('/api/travelShareOrder/cancel/:id', controller.business.travelShareOrder.cancel);
  router.resources('travelShareOrder', '/api/travelShareOrder', controller.business.travelShareOrder);
  router.resources('travelOrder', '/api/travelOrder', controller.business.travelOrder);
  router.resources('travelOrderItem', '/api/travelOrderItem', controller.business.travelOrderItem);


  // 旅游方案定制
  router.get('/api/travelCustom/list', controller.business.travelCustom.list);
  router.resources('travelCustom', '/api/travelCustom', controller.business.travelCustom);
  // 用户动态
  router.get('/api/userPost/list', controller.business.userPost.list);
  router.resources('userPost', '/api/userPost', controller.business.userPost);
  // 用户动态点赞
  router.post('/api/userPost/unlike/:id', controller.business.userPostLike.unlike);
  router.post('/api/userPost/like/:id', controller.business.userPostLike.like);

  /**
   * 用户账户
   */
  // 充值
  // 创建支付订单
  router.post('/api/recharge/payment/wx', controller.payment.recharge.createPayment);
  // 支付回调
  router.post('/api/recharge/payment/wx/notify', controller.payment.recharge.paymentWxNotify);
  router.post('/api/recharge/payment/wx/refund/notify', controller.payment.recharge.refundWxNotify);
  router.get('/api/recharge/list', controller.common.recharge.list);
  router.post('/api/recharge/refund', controller.common.recharge.refund);
  router.post('/api/recharge/refund/confirm', controller.common.recharge.refundConfirm);
  router.resources('recharge', '/api/recharge', controller.common.recharge);
  
  // 余额记录
  router.get('/api/balanceRecord/list', controller.business.balanceRecord.list);
  router.post('/api/balanceRecord/recharge', controller.business.balanceRecord.createRecharge);
  // router.post('/api/balanceRecord/payment/wx', controller.business.balanceRecord.paymentWx);
  // router.get('/api/merchant/balanceRecord/todayIncome', controller.business.balanceRecord.getTodayIncome);
  router.get('/api/balanceRecord/todayTotal', controller.business.balanceRecord.todayTotal);
  router.post('/api/balanceRecord/withdraw/notify', controller.payment.withdraw.withdrawNotify);
  router.post('/api/balanceRecord/withdraw', controller.business.balanceRecord.withdraw);
  // 重试提现
  router.post('/api/balanceRecord/withdraw/retry', controller.business.balanceRecord.retryWithdraw);
  router.resources('balanceRecord', '/api/balanceRecord', controller.business.balanceRecord);
  /**
   * 租户
   */
  router.get('/api/qrcode', controller.common.qrcode.getQrcode);

  // 租户登录/system/auth/login
  router.post('/api/system/auth/login', controller.system.systemUser.login)
  // 获取租户信息和权限
  router.get('/api/system/auth/get-permission-info', middleware.auth(), controller.system.systemUser.getUserInfo)
  router.resources('/api/system/user', middleware.auth(), controller.system.systemUser);
  // 租户菜单
  router.get('/api/system/menu/tree', middleware.auth(), controller.system.systemMenu.tree);
  router.resources('/api/system/menu', middleware.auth(), controller.system.systemMenu);
  // 角色
  router.get('/api/system/role/list', middleware.auth(), controller.system.systemRole.list);
  router.resources('/api/system/role', middleware.auth(), controller.system.systemRole);
  // 权限
  router.get('/api/system/permission/list-user-roles', middleware.auth(), controller.system.systemPermission.getUserRoles);
  router.post('/api/system/permission/assign-user-role', middleware.auth(), controller.system.systemPermission.updateUserRoles);
  router.get('/api/system/permission/list-role-menus', middleware.auth(), controller.system.systemPermission.listRoleMenus);
  router.post('/api/system/permission/assign-role-menu', middleware.auth(), controller.system.systemPermission.updateRoleMenus);
};
